function request(callback) {
  // var userId = "995206668561625088"
  var userId = getApp().globalData.userId
  getApp().func.Post(false, getApp().api.user_address, { "userId": userId},
    function (data) {
      typeof callback == "function" && callback(data)
    },
    function (error) {
      wx.hideLoading()
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    }
  )


};

function chooseAddress(addressId, suc, fail) {
  getApp().func.Post(false, getApp().api.choose_address,
    { "userId": getApp().globalData.userId, "addressId": addressId },
    function (data) {
      if (data.code == 200) {
        typeof suc == "function" && suc(data)
      } else {
        typeof fail == "function" && fail("设置失败")
      }
    },
    function (error) {
      typeof fail == "function" && fail(error)
    })
}

function requestAdd(obj, callback) {
  getApp().func.Post(false, getApp().api.user_add_address, obj,
    function (data) {
      typeof callback == "function" && callback(data)
    },
    function (error) {
      wx.hideLoading()
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    }
  )
};

function requestDelete(addressId, callback) {
  getApp().func.Get(true, getApp().api.user_delete_address, { "addressId": addressId},
    function (data) {
      typeof callback == "function" && callback(data)
    },
    function (error) {
      wx.hideLoading()
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    }
  )
};



module.exports = {
  request: request,
  requestAdd: requestAdd,
  requestDelete: requestDelete,
  chooseAddress: chooseAddress
};